<?php

namespace App\Http\Controllers\Admin;
;

use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Crypt;
use App\Http\Model\User;
require_once '../resources/org/code/Code.class.php';
class LoginController extends CommonController
{
    //
    public function login()
    {
       if($input = Input::all()){
           $code = new \Code();
           $_code = $code->get();
           if(strtoupper($input['code'])!=$_code){
               return back()->with('msg','验证码错误');
           }

           $user = User::first();
           if($user->user_name != $input['user_name']&&Crypt::decrypt($user->user_pass) != $input['user_pass'] ){
               return back()->with('msg','用户名或者密码错误');
           }
           session(['user'=>$user]);
           return redirect('admin/index');
       }else{
           return view('admin.login');
       }
    }
    public function quit()
    {
        session(['user'=>null]);
        return redirect('admin/login');
    }
    public function code()
    {
        $code = new \Code();
        $code->make();
    }
    public function crypt()
    {
        $str = '123456';
        $str_p = 'eyJpdiI6ImtmVFltek9ER2huZlU0OWpxZmVNOFE9PSIsInZhbHVlIjoiS1ZaZ1UxNDZLd3o1UGZIZ0MxRG5XUT09IiwibWFjIjoiY2Q4YWE5MDE3MmRkMzNlYTNjMzkxYmZmZmY0NDM1YWM2Mzc1ZmMzZWRjMTAzMGYwMzEwMTM5MzRkMDE2YTQ2ZSJ9';
        echo Crypt::encrypt($str);
        echo "<br/>";
        echo Crypt::decrypt($str_p);


    }

}
